package cn.tk.engine.mr;

import cn.tk.model.pojo.mr.engine.MrReq;
import com.alibaba.ttl.TransmittableThreadLocal;

/**
 * Created by denglw on 2020/7/16.<br/>
 * Desc: 维护多轮对话请求对象
 */
public class MrReqContext {

    static ThreadLocal<MrReq> context = new TransmittableThreadLocal<>();

    public static void setContext(MrReq req) {
        context.set(req);
    }

    public static MrReq getContext() {
        return context.get();
    }

    public static void removeContext() {
        context.remove();
    }

    /**
     * 获取当前请求消息id<br/>
     * @return 消息id
     */
    public static String currMessageId() {
        MrReq context = getContext();
        if (context == null) {
            return "";
        }
        return context.getMessageId();
    }

}
